package core
{
	import core.controller.SkinLayoutManager;
	import core.view.ProgressView0;
	import core.view.ToolBarView;
	import core.view.VideoView;
	
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	
	import org.ais.system.Ais;
	import org.aisy.display.USprite;

	[SWF(backgroundColor=0x111111, width=700, height=400)]
	public class Main extends USprite
	{
		static public var IS:Main;
		public var isClear:Boolean;
		public var isLocal:Boolean;
		
		public function Main()
		{
		}
		
		public function connect(im:*):void
		{
			isLocal = Boolean(parseInt(loaderInfo.parameters["isLocal"]));
			if (Ais.IMain.Swf.hasKey("UNETSTREAMY_IMOON") === -1) {
				throw new Error("Not found name: UNETSTREAMY_IMOON, url: unetstreamy_imoon.swf! Please check imoon.");
			}
			
			Main.IS = this;
			
			Ais.IMain.stage.scaleMode = StageScaleMode.NO_SCALE;
			Ais.IMain.stage.align = StageAlign.TOP_LEFT;
			
			this.addChild(VideoView.getInstance());
			this.addChild(ToolBarView.getInstance());
			this.addChild(ProgressView0.getInstance());
			SkinLayoutManager.getInstance();
			
			Ais.IMain.addChild(this);
			
			Ais.IMain.stage.dispatchEvent(new Event(Event.RESIZE));
			
			im = null;
		}
		
		override public function clear():void
		{
			if (isClear === true) return;
			isClear = true;
			try {
				SkinLayoutManager.getInstance().clear();
				ProgressView0.getInstance().clear();
				ToolBarView.getInstance().clear();
				VideoView.getInstance().clear();
				super.clear();
			}
			catch (error:Error) {}
			IS = null;
		}
		
	}
}